package com.example.lanouhn.firstapp.activity.utils;

import com.alibaba.fastjson.JSON;
import com.example.lanouhn.firstapp.activity.model.SearchGoodsList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/7/24.
 */
public class SearchGoodsListJson {
    /**
     * 解析首页搜索按钮跳转到 搜索商品界面
     *
     * @param json
     * @return
     */
    public static List<SearchGoodsList> getSearchGoodsList(String json) {
        //创建数组来储存数据
        List<SearchGoodsList> list = new ArrayList<>();

        try {
            JSONObject obj = new JSONObject(json);
            //获取解析的数据
            String data = obj.getString("datas");

            JSONObject jsonObject = new JSONObject(data);
            //解析数据
            JSONArray array = jsonObject.getJSONArray("goods_list");

            //使用fastJson解析
            list = new ArrayList<SearchGoodsList>(JSON.parseArray(array.toString(), SearchGoodsList.class));

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return list;

    }
}


